package com.magic.gre.ui.dialog;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.magic.gre.R;
import com.magic.gre.base.dialog.BaseCenterDialog;
import com.noname.lib_base_java.glide.LoadImageUtils;
import com.noname.lib_base_java.util.L;
import com.noname.lib_base_java.util.PathUtil;
import com.noname.lib_base_java.util.ToastUtil;

/**
 * Author: Lmoumou
 * Date: 2019-01-10 10:05
 * 文件名: AvtivityDialog
 * 描述:
 */
public class AvtivityDialog extends BaseCenterDialog {

    private String activityId;
    private ImageView codeIv;
    private String applyImage;
    private OnActivityDialogListener onActivityDialogListener;

    public void setOnActivityDialogListener(OnActivityDialogListener onActivityDialogListener) {
        this.onActivityDialogListener = onActivityDialogListener;
    }

    @Override
    protected void initView(View view) {
        final EditText wxEdt = view.findViewById(R.id.wx_edt);
        codeIv = view.findViewById(R.id.code_iv);
        L.e("LLLSSQQ","url->"+PathUtil.imgPath(applyImage));
        LoadImageUtils.loadImage(PathUtil.imgPath(applyImage), codeIv);
        view.findViewById(R.id.signup_tv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = String.valueOf(wxEdt.getText());
                if (TextUtils.isEmpty(s)) {
                    ToastUtil.getInstance().showNormal(mContext, "请输入微信号");
                    return;
                }
                if (onActivityDialogListener != null) {
                    dismissThis(isResumed());
                    onActivityDialogListener.onSingUp(activityId, s);
                }
            }
        });

        view.findViewById(R.id.qa_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onActivityDialogListener != null) {
                    onActivityDialogListener.onQA();
                }
            }
        });
    }

    @Override
    protected Float setDialogWith() {
        return 0.9F;
    }

    @Override
    protected int setViewId() {
        return R.layout.dialog_activity;
    }


    public void showThis(FragmentManager manager, String tag, String activityId, String applyImage) {
        super.showThis(manager, tag);
        this.activityId = activityId;
        this.applyImage = applyImage;
    }

    @Override
    protected void initBundle(Bundle bundle) {

    }


    public interface OnActivityDialogListener {
        void onSingUp(String activityId, String wechatNum);

        void onQA();
    }
}
